package com.gitee.xhs.sourceIterator;

import com.gitee.xhs.enums.OnTimeEnum;
import com.gitee.xhs.enums.RegularEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author BigHead
 * @date 2022/7/25 16:02
 * @description SkipRateLimitedIterator
 */
public class SkipRateLimitedIterator<IT, T extends AbstractSourceIterator<IT>> extends AbstractRateLimitedIterator<IT, T> {

    private static final Logger logger = LoggerFactory.getLogger(SkipRateLimitedIterator.class);

    private CheckSkipInterface<IT> checkSkip;

    public SkipRateLimitedIterator(AbstractSourceIterator<IT> inner) {
        super(inner);
    }

    public SkipRateLimitedIterator(AbstractSourceIterator<IT> inner, Integer groupDataNum, OnTimeEnum onTimeEnum, Integer intervalTime, RegularEnum regularEnum) {
        super(inner, groupDataNum, onTimeEnum, intervalTime, regularEnum);
    }

    public CheckSkipInterface<IT> getCheckSkip() {
        return checkSkip;
    }

    public void setCheckSkip(CheckSkipInterface<IT> checkSkip) {
        this.checkSkip = checkSkip;
    }

    @Override
    public boolean hasNext() {
        return inner.hasNext();
    }

    @Override
    public IT next() {
        return skipSpecificData();
    }

    private IT skipSpecificData() {
        IT object = prepareIteratorData();
        if (null != checkSkip) {
            while (checkSkip.checkSkip(object)) {
                object = prepareIteratorData();
            }
        }
        return object;
    }


}
